<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>用户注册</title>
    <link rel="stylesheet" href="css/perfBillCss/comment.css"/>
    <link rel="stylesheet" href="css/shareQRcode/registerrll.css?t=683934"/>
</head>
<body style="background-color:#ffffff;">
<div id="registerWrapper">
    <div class="infmBox">
        <span class="leftText">手机号码</span><input type="tel" name="" id="tel" class="infmInput" value=""
                                                 placeholder="请在这里输入" maxlength="11"/>
    </div>
    <div class="infmBox">
        <span class="leftText">图形验证码</span><input type="text" name="" id="capt" class="infmInput" value=""
                                                  placeholder="请在这里输入"/><img
            src="https://bj-img2017.oss-cn-beijing.aliyuncs.com/admin/h5/images/register/gengxin@2x.png" alt=""
            class="picCode"/>
    </div>
    <div class="infmBox">
        <span class="leftText">短信验证码</span><input type="number" name="" id="vfyCode" class="infmInput" value=""
                                                  placeholder="请在这里输入"/><input type="button" id="getcode" value="获取验证码">
    </div>
    <div class="infmBox">
        <span class="leftText">真实姓名</span><input type="text" name="" id="realName" class="infmInput" value=""
                                                 placeholder="请在这里输入" maxlength="20"/>
    </div>
    <div class="infmBox">
        <span class="leftText">登录密码</span><input type="password" name="" id="loginPsd" class="infmInput" value=""
                                                 placeholder="请在这里输入"/>
    </div>
    <!--<div class="infmBox">
        推广码：<input type="number" name="" class="bgWhite" id="extendCode" value="" placeholder="请输入推广码"/>
    </div>-->
    <div class="isAgree">
        <span id="isAgree"><input type="hidden" value="1" class="isAgreeStatus"/><img
                src="https://bj-img2017.oss-cn-beijing.aliyuncs.com/admin/h5/images/register/huiju/wei.png"
                class="statusImg" alt=""/>我已阅读并同意</span><a href="http://121.41.29.107:9999/huiju/register"
                                                           class="regProtocol">《用户注册协议》</a>
    </div>
    <div class="register">我要注册</div>
    <p class="tipText">提示：注册后下载APP即使用</p>
    <div class="download">下载APP</div>
</div>
<script type="text/javascript" src="js/perfBillJs/jquery.min.js"></script>
<script type="text/javascript" src="js/jsmain.js"></script>
<script type="text/javascript" src="js/perfBillJs/adaptive-version2.js"></script>
<script type="text/javascript" src="js/perfBillJs/main.js"></script>
<script type="text/javascript" src="js/perfBillJs/md5.js"></script>

<script type="text/javascript">
    $(function () {

        // 定义全局变量
        var imgCode; // 用户输入的图片验证码
        var imgKey;  // 获取图片验证时返回的唯一标志
        var phone;   // 发送短信验证码的手机号
        var verfKey; // 短信验证码接口返回的唯一标志
        var merMobile = GetQueryString('merMobile');// 推荐人手机号从请求中获取
        $("#extendCode").val(merMobile);// 推荐人手机号
        var i = 1;
        var appDataObjNw = appData();

        $("#getcode").on("click", function () {
            var tel = $("#tel").val().trim();
            if (tel == "" || tel == null) {
                tipInfm("请输入注册手机号");
            } else if (!/^1[3|4|5|6|7|8|9]\d{9}$/.test(tel)) {
                tipInfm("手机格式不正确");
            } else {
                getSmscode(this); // 请求后台
                /* count(this); */
            }
        });

        //刷新图片
        $(".picCode").on("touchend", function () {
            imgVerificationCode(); // 调用
        });
        /* 是否同意注册协议 */
        $("#isAgree").click(function () {
            if ($(this).find(".isAgreeStatus").val() == "0") {
                $(this).find(".isAgreeStatus").val("1");
            } else {
                $(this).find(".isAgreeStatus").val("0");
            }
            if ($(this).find(".isAgreeStatus").val() == "0") {
                $(this).find(".statusImg").attr("src", "https://bj-img2017.oss-cn-beijing.aliyuncs.com/admin/h5/images/register/huiju/xuan.png");
            } else {
                $(this).find(".statusImg").attr("src", "https://bj-img2017.oss-cn-beijing.aliyuncs.com/admin/h5/images/register/huiju/wei.png");
            }
        })

        imgVerificationCode(); // 调用
        // 获取图片验证码
        function imgVerificationCode() {
            var appDataObj = appData();
            var postJson = JSON.stringify(appDataObj);
            // 获取图片二维码
            postJsonAjax("../../v1/verify/img.json?tokenId=" + appDataObj.tokenId, postJson, true, function (i, data) {
                imgKey = data.data.imgKey;  // 获取图片验证时返回的唯一标志
                $(".picCode").attr("src", "data:image/jpg;base64," + data.data.imgBase64);
            });
        }

        // 发送短信验证码
        function getSmscode(that) {
            var appDataObj = appData();
            imgCode = $("#capt").val();
            phone = $("#tel").val();
            appDataObj.data = {
                imgCode: imgCode,
                imgKey: imgKey,
                phone: phone
            };
            var postJson = JSON.stringify(appDataObj);
            // 获取短信验证码
            postJsonAjax("../../v1/smscode/send.json?tokenId=" + appDataObj.tokenId, postJson, true, function (i, data) {
                // 记录短信验证码返回的唯一标识
                verfKey = data.data; // 赋值到全局变量
                if (data.code == '0017') {
                    tipInfm("图片验证码错误");
                    imgVerificationCode(); // 重新获取图片验证码
                } else {
                    count(that);
                }
            });
        }

        function checkFun() {
            var tel = $("#tel").val().trim();
            var capt = $("#capt").val().trim();
            var vfyCode = $("#vfyCode").val().trim();
            var realName = $("#realName").val().trim();
            var loginPsd = $("#loginPsd").val().trim();
            if (tel.length == 11 && capt != "" && vfyCode != "" && realName != "" && loginPsd != "") {
                $(".register").css("opacity", "1");
            } else {
                $(".register").css("opacity", "0.6");
            }
        }

        $(".infmInput").bind("input propertychange", function () {
            checkFun();
        })


        // 判断手机号是否已注册
        function checkMobileNo() {
            var appDataObj = appData();
            var loginName = $("#tel").val().trim(); 		// 注册手机号，登陆账号
            appDataObj.data = {
                mermobile: loginName,
                plaid: appDataObj.plaId
            };
            var postJson = JSON.stringify(appDataObj);
            // 请求判断手机号是否已注册接口
            postJsonAjax("../../v1/user/checkphone.json?tokenId=" + appDataObj.tokenId, postJson, true, function (i, data) {
                registerflag = data.code;
                if (registerflag == '0015') {
                    tipInfm("该手机号已注册");
                } else if (registerflag == '0000') {
                    registerCommit(); // 提交注册信息
                } else {
                    tipInfm("注册失败");
                }
            });
        }

        // 提交注册
        function registerCommit() {
            var appDataObj = appData();
            var loginName = $("#tel").val().trim(); 		// 注册手机号，登陆账号
            var loginPass = hex_md5($("#loginPsd").val().trim()).toUpperCase();	// 用户登陆密码(需要MD5加密)
            var merName = $("#realName").val().trim(); 	// 用户名(用户真实姓名)
            var verifyCode = $("#vfyCode").val().trim(); 	// 短信验证码
            var referphone = merMobile;				// 推荐人手机号(从请求地址中获取)
            appDataObj.data = {
                loginName: loginName,
                loginPass: loginPass,
                merName: merName,
                plaId: appDataObj.plaId,
                referphone: referphone,
                verifyCode: verifyCode,
                verfKey: verfKey
            };
            var postJson = JSON.stringify(appDataObj);
            // 请求注册接口
            postJsonAjax("../../v1/user/adduser.json?tokenId=" + appDataObj.tokenId, postJson, true, function (i, data) {
                if (data.code == '0014') {
                    tipInfm("短信验证码错误");
                    imgVerificationCode(); // 重新获取图片验证码
                } else if (data.code == '0000') {
                    tipInfm("注册成功");
                    // 注册成功后的跳转至success页
                    window.location.href = "../share/result.html?plaId=" + appDataObj.plaId + "&appId=" + appDataObj.appId;
                } else {
                    tipInfm("注册失败");
                }
            });
        }

        // 注册按钮点击事件
        $(".register").on("touchend", function () {
            var tel = $("#tel").val();
            var capt = $("#capt").val();
            var vfyCode = $("#vfyCode").val();
            var realName = $("#realName").val();
            var loginPsd = $("#loginPsd").val();
            var extendCode = $("#extendCode").val();
            var isAgreeStatus = $(".isAgreeStatus").val();
            var regPsd = /^[a-zA-Z0-9]{6,18}$/.test(loginPsd);
            var regName = /^(([a-zA-Z+\.?\·?a-zA-Z+]{2,30}$)|([\u4e00-\u9fa5+\·?\u4e00-\u9fa5+]{2,30}$))/.test(realName);
            if (tel == "" || tel == null) {
                tipInfm("请输入注册手机号")
            } else if (!/^1[3|4|5|6|7|8|9]\d{9}$/.test(tel)) {
                tipInfm("手机格式不正确");
            } else if (capt == "" || capt == null) {
                tipInfm("请输入图形验证码");
            } else if (vfyCode == "" || vfyCode == null) {
                tipInfm("请输入验证码");
            } else if (realName == "" || realName == null) {
                tipInfm("请输入真实姓名");
            }
            /* else if(!regName){
             tipInfm("姓名不合法");
             } */
            else if (loginPsd == "" || loginPsd == null) {
                tipInfm("请输入登录密码");
            } else if (!regPsd) {
                tipInfm("登录密码请输入6-18位数字或字母");
            } else if (isAgreeStatus == "" || isAgreeStatus == null || isAgreeStatus == "1") {
                tipInfm("请先同意协议后再注册");
                /* }else if(extendCode==""||extendCode==null){
                 tipInfm("请输入推广码"); */
            } else {
                checkMobileNo(); // 检测是否已注册
            }
        });

        // 点击下载按钮
        $(".download").click(function () {
            // 点击下载按钮跳转到下一页
            window.location.href = "../share/download_fs.html?plaId=" + appDataObjNw.plaId + "&appId=" + appDataObjNw.appId;
        });

    })

    /* $(function(){
     var appandurl; // 安卓下载地址
     var appiosurl; // ios下载地址
     var appDataObj;
     appDataObj = appData();
     var postJson = JSON.stringify(appDataObj);
     // 获取app信息
     postJsonAjax("../../v1/app/details.json?tokenId="+appDataObj.tokenId, postJson, true, function(i, data) {
     appandurl = data.appandurl;
     appiosurl = data.appiosurl;
     });
     }); */
</script>
</body>
</html>
